<template>
	<view class="page-index">
		<uni-search-bar @confirm="getList()" placeholder='请输入关键词' bgColor='#ffffff' v-model="form.search" radius="33">
		</uni-search-bar>
		<view class="sticky">
			<DropDown @getForm='getForm' :forms='form' :area='areaList' ref='drop' style='z-index: 5;' />
		</view>
		<Work :workList="workList" :total='total' v-if="Type==0" text="暂无数据" :status='status' :Type='Type' />
		<Recruit :resumeList="workList" :total='total' v-if="Type==1" text="暂无数据" :status='status' :Type='Type' />
		<view :class="[scrollTop>=150?'backTop':'backNone']" @click="scroll">
			<text class='iconfont fontclassrocket' style='font-size: 42rpx;'></text>
		</view>
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	import * as user from '@/api/user.js'
	import DropDown from '@/components/home/DropDown/index.vue'
	import Work from '@/components/home/work/index.vue'
	import Recruit from '@/components/home/recruit/index.vue'
	export default {
		components: {
			DropDown,
			Work,
			Recruit
		},
		data() {
			return {
				resume_forward:'',//增加次数
				title: '', //分享标题
				imgage: '', //分享图片
				scrollTop: 0,
				status: 'more',
				total: -1,
				Type: uni.getStorageSync('Type'), //身份
				form: {
					page: 1,
					pages: '',
					neqId: '',
					search: '',
					member_id: '',
					drving_id: '',
					age_id: '',
					welfare_id: '',
					salary_id: '',
					position_id2: '',
					position_id: '',
					areas_pid: '',
					areas_id: '',
					secondary: '',
					is_index: '',
					gender: 2,
					refresh_time: '',
					date: ''
				}, //搜索参数
				workList: [], //需求列表
				search: {},
				areaList: [{
						title: '接单区域',
						type: 'areas',
						id: ''
					},
					{
						title: '接单信息',
						type: 'position',
						id: ''
					},
					{
						title: '薪资范围',
						type: 'salary',
						id: ''
					},
					{
						title: '更多',
						type: 'more',
						id: ''
					}
				]
			}
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				user.wxForwardGetAward({
					type: 0
				}).then(res => {
					// 关闭弹窗
				})
			}
			return {
				title: this.title, //分享标题
				imageUrl: this.imgage,
				path: '/pages/home/index',
			}
		},
		onLoad(params) {
			if (params.params) {
				// uni.$emit('qqq',JSON.parse(params.params))
				setTimeout(res=>{
					this.$refs.drop.getDrop(JSON.parse(params.params));
				},1000)
				if (JSON.parse(params.params).type == 'secondary') {
					this.form.secondary = JSON.parse(params.params).id
					this.areaList[3].title = ' 更多'
					this.getPosotionList()
				} else {
					if (JSON.parse(params.params).pid == 0) {
						this.form.position_id = JSON.parse(params.params).id
						// this.form.secondary = JSON.parse(params.params).id
						this.areaList[1].title = JSON.parse(params.params).title
						this.$forceUpdate()
					}
					this.getPosotionList()
				}
				// uni.$emit('yes',params.params)
			}
		},
		onShow() {
			this.nameGetConfig()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		onReachBottom() {
			// console.log('gg');
			this.form.page += 1
			if (uni.getStorageSync('Type') == 1) {
				this.getResumeList()
			} else {
				this.getPosotionList()
			}
		},
		methods: {
			// 获取分享图片
			nameGetConfig() {
				index.nameGetConfig({
					name: 'wx_share_image,wx_share_title,resume_forward'
				}).then(res => {
					this.imgage = res.data.wx_share_image
					this.title = res.data.wx_share_title
					this.resume_forward = res.data.resume_forward
					if (uni.getStorageSync('shareType') == 1) {
						uni.showToast({
							icon: 'none',
							title: `查看需求已+${res.data.resume_forward}条,\n感谢您助力鱼台就业。`,
							duration: 2000
						});
						uni.removeStorageSync('shareType');
					}
				})
			},
			//DropDown传值
			getForm(obj) {
				var e = JSON.parse(JSON.stringify(obj))
				this.form.areas_id = e.areas_id
				this.form.age_id = e.age_id
				this.form.drving_id = e.drving_id
				this.form.position_id = e.position_id
				this.form.position_id2 = e.position_id2
				this.form.salary_id = e.salary_id
				this.form.secondary = e.secondary
				this.form.refresh_time = e.refresh_time
				this.form.welfare_id = e.welfare_id.toString()
				this.form.page = 1
				this.workList = []
				this.getList()
			},
			getList() {
				this.workList = []
				if (uni.getStorageSync('Type') == 1) {
					this.getResumeList()
				} else {
					this.getPosotionList()
				}
			},
			//获取需求列表
			getPosotionList() {
				this.status = 'loading'
				index.getPosotionList(this.form).then(res => {
					this.workList.push(...res.data.data)
					this.total = res.data.total
					setTimeout(() => {
						if (res.data.current_page < res.data.last_page) {
							this.status = 'more'
						} else {
							this.status = 'noMore'
						}
					}, 200)
				})
			},
			getResumeList() {
				this.status = 'loading'
				index.getResumeList(this.form).then(res => {
					this.workList.push(...res.data.data)
					this.total = res.data.total
					setTimeout(() => {
						if (res.data.current_page < res.data.last_page) {
							this.status = 'more'
						} else {
							this.status = 'noMore'
						}
					}, 200)
				})
			},
			scroll() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 200
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.page-index {
		.sticky {
			position: sticky;
			top: 0;
			background: #F5F5F5;
			z-index: 2;
		}

		.backTop {
			display: inline-block;
			z-index: 5;
			position: fixed;
			bottom: 100rpx;
			right: 50rpx;
			width: 80rpx;
			height: 80rpx;
			background: #ff6600;
			transition-duration: 0.5s;
			border-radius: 8rpx;
			text-align: center;
			line-height: 80rpx;
			color: #ffffff;
			border-radius: 50%;
		}

		.backNone {
			display: inline-block;
			z-index: 5;
			position: fixed;
			bottom: 100rpx;
			right: -100rpx;
			width: 80rpx;
			height: 80rpx;
			color: transparent;
			// background: #ff6600;
			transition-duration: 0.5s;
			border-radius: 8rpx;
			text-align: center;
			line-height: 80rpx;
			border-radius: 50%;
		}
	}
</style>
